package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liudo
 * @version 1.0
 * @project mq-demo
 * @description 话题交换机配置
 * @date 2023/8/19 15:03:42
 */
// @Configuration
public class TopicConfiguration {

    @Bean
    public Queue topicQueue1() {
        return QueueBuilder.durable("topic.queue1").build();
    }

    @Bean
    public Queue topicQueue2() {
        return QueueBuilder.durable("topic.queue2").build();
    }

    @Bean
    public TopicExchange topicExchange() {
        return ExchangeBuilder.topicExchange("topic.exchange").build();
    }
    // * 代表一个词 #代表一串词
    @Bean
    public Binding topicBinding1() {
        return BindingBuilder.bind(topicQueue1())
                .to(topicExchange()).
                with("hf.*");
    }

    @Bean
    public Binding topicBinding2() {
        return BindingBuilder.bind(topicQueue1())
                .to(topicExchange())
                .with("*.news");
    }

    @Bean
    public Binding topicBinding3() {
        return BindingBuilder.bind(topicQueue2())
                .to(topicExchange())
                .with("fy.*");
    }

    @Bean
    public Binding topicBinding4() {
        return BindingBuilder.bind(topicQueue2())
                .to(topicExchange())
                .with("*.weather");
    }

    @Bean
    public Binding topicBinding5() {
        return BindingBuilder.bind(topicQueue1())
                .to(topicExchange()).
                with("hf.#");
    }

}
